package com.Maybe.book.config;


import com.Maybe.book.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@ControllerAdvice
@ResponseBody
//@RestControllerAdvice
public class ExceptionAdvice {
    //异常统一处理
    @ExceptionHandler(Exception.class)
    public Result handler(Exception e){
        log.error("发生异常,e:",e);
        return Result.fail("内部错误，请联系管理员");
    }
    @ExceptionHandler(NullPointerException.class)
    public Result handler2(Exception e){
        log.error("发生异常,e:",e);
        return Result.fail("发生空指针异常");

    }
    @ExceptionHandler(IndexOutOfBoundsException.class)
    public Result handler3(Exception e){
        log.error("发生异常,e:",e);
        return Result.fail("发生数组越界异常");

    }
//    @ExceptionHandler
//    public Result handler4(NullPointerException e){
//        log.error("发生异常,e:",e);
//        return Result.fail("发生空指针越界异常");
//    }



}
